package com.easyj.admin.edu.serviceimpl;

import org.activiti.api.process.model.ProcessInstance;
import org.activiti.api.process.runtime.ProcessRuntime;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.easyj.admin.db.mapper.SocialJobMapper;
import com.easyj.admin.db.model.SocialJob;
import com.easyj.base.enums.Level2ApplyStatusEnum;

/**
 * 并行审批结束后，修改状态
 * @author hjf
 *
 */
@Service("socialJobApproveListener")
public class SocialJobApproveListener implements ExecutionListener{

	private static final long serialVersionUID = 1L;
	
	@Autowired
    private ProcessRuntime processRuntime;
	
	@Autowired
	private  SocialJobMapper socialJobMapper;

	@Override
	@Transactional
	public void notify(DelegateExecution execution) {
	   //System.out.println("+++++socialJobApproveListener+++");	
	   Boolean officePass=(Boolean)execution.getVariable("officePass");
	   Boolean eduPass=(Boolean)execution.getVariable("eduPass");
	   String procId=execution.getProcessInstanceId();
	   ProcessInstance process=processRuntime.processInstance(procId);
	   Long entityId=Long.parseLong(process.getBusinessKey());
	   //delegateTask.getTaskDefinitionKey()
	   if(officePass&&eduPass) {
		   SocialJob entity=new SocialJob();
		   entity.setId(entityId);
		   entity.setStatus(Level2ApplyStatusEnum.WaitAudit.getKey());
		   socialJobMapper.updateByPrimaryKeySelective(entity);
	   }else {
		   SocialJob entity=new SocialJob();
		   entity.setId(entityId);
		   entity.setStatus(Level2ApplyStatusEnum.Repeat.getKey());
		   socialJobMapper.updateByPrimaryKeySelective(entity);
	   }
	}


}
